package com.lxmes.common.utils;

import java.math.BigDecimal;

public class DzGeneraRuleUtils {

    /*
    * @生成规格型号
    * @param 参数：法兰台高F，法兰内径系列I，法兰内径系列Ⅱ，公称压力PN，公称通径DN
    * */
    public static String generaGgxh(String fltgF,String flnj1,String flnj2,String gcylPn,String gctjDn){
        StringBuffer ggxhStr = new StringBuffer();
        if(StringUtils.isEmpty(fltgF)||"0".equals(fltgF)){
            ggxhStr.append("FF");
        }else{
            ggxhStr.append("RF");
        }
        ggxhStr.append(gcylPn);
        ggxhStr.append("-");
        ggxhStr.append(gctjDn);

        if(!StringUtils.isEmpty(flnj1)&&!"0".equals(flnj1)){
            ggxhStr.append("A");
        }
        if(!StringUtils.isEmpty(flnj2)&&!"0".equals(flnj2)){
            ggxhStr.append("B");
        }

        return ggxhStr.toString();
    }


    /*
    * 生成物料识别码
    * 参数：标准简码,规格型号,法兰厚度C,法兰密封面尺寸d,法兰台高f,法兰外径D,法兰内径,法兰盖厚度C
    * */
    public static String generaWlsbm(String itemBzSimCode,String ggxh,String flhdC,String flmfmccD,String fltgF,String flwjD,String flnj,String flghdC){
        StringBuffer wlsbm = new StringBuffer();

        wlsbm.append(itemBzSimCode).append(ggxh).append("-")
                .append(flhdC).append("-").append(flmfmccD)
                .append("-").append(fltgF).append("-").append(flwjD)
                .append("-").append(flnj).append("-").append(flghdC);

        return wlsbm.toString();
    }
    /*
     * 生成物料编号 取物料识别码的规格型号、第二与第三间隔及之间的数值、第五间隔以后的数值
     * 参数：规格型号、物料分类、物料标识码
     * */
    public static String generaItemId(String classId,String spec,String itemIdentifyCode){
        StringBuffer generaItemId = new StringBuffer();
        String[] str=itemIdentifyCode.split("-");
        generaItemId.append(classId).append(spec).append("-")
                .append(str[2]).append("-").append(str[5]).append("-")
                .append(str[6]).append("-").append(str[7]);
        return generaItemId.toString();
    }

/*    public static void main(String[] args) {

        String[] str="LLRF16-16\"A-38-490-4-580-411-0".split("-");
            System.out.println(str.length);
        for (int i = 0; i <str.length ; i++) {
            System.out.println(str[i]);

        }
        StringBuffer generaItemId = new StringBuffer();
        generaItemId.append("C").append("RF16-16\"A").append("-")
                .append(str[2]).append("-").append(str[5]).append("-")
                .append(str[6]).append("-").append(str[7]);
        System.out.println(generaItemId.toString());

    }*/


    /*
     * 生成法兰内径
     * 参数：法兰内径系列I，法兰内径系列Ⅱ
     * */
    public static String generaFlnj(String flnj1,String flnj2){
        String flnj = "";
        if(!StringUtils.isEmpty(flnj1)&&!"0".equals(flnj1)){
            flnj = flnj1;
        }
        if(!StringUtils.isEmpty(flnj2)&&!"0".equals(flnj2)){
            flnj = flnj2;
        }
        return flnj;
    }

    /*
     * 计算重量
     * 参数：法兰外径D，法兰内径系列I，法兰内径系列Ⅱ，法兰厚度C，法兰密封面尺寸d，法兰台高f，法兰孔径L，法兰孔数n
     * */
    public static Double generaJszl(String flwjD,String flnj1,String flnj2,String flhdC,String flmfmccD,String fltgF,String flkjL,String flksN){
      Double jszl= new Double(0.0);
        Double flnj = Double.parseDouble(generaFlnj(flnj1, flnj2));
        Double flwjD2 = Double.parseDouble(flwjD);
        Double flhdC2 = Double.parseDouble(flhdC);
        Double flmfmccD2 = Double.parseDouble(flmfmccD);
        Double fltgF2 = Double.parseDouble(fltgF);
        Double flkjL2 = Double.parseDouble(flkjL);
        Double flksN2 = Double.parseDouble(flksN);
        jszl = (flwjD2-(flwjD2-flnj)/2)*((flwjD2-flnj)/2)*0.02466*flhdC2/1000-(flwjD2-(flwjD2-flmfmccD2)/2)*((flwjD2-flmfmccD2)/2)*0.02466*fltgF2/1000-flkjL2*flkjL2*6.17*(flhdC2-fltgF2)*flksN2/1000000;
        BigDecimal two = new BigDecimal(jszl);
        double resultDouble = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        return resultDouble;
    }

    /*
     * 计算下料重量
     * 参数：法兰外径D，法兰内径系列I，法兰内径系列Ⅱ，法兰厚度C，法兰台高f，公称通径DN，
     * */
    public static Double jsxlzl(String flwjD,String flnj1,String flnj2,String flhdC,String fltgF,String gctjDn){
        Double xlzl= new Double(0.0);
        /*(法兰外径D+10-(((法兰外径D+10)-(法兰内径-10))/2))*(((法兰外径D+10)-(法兰内径-10))/2)*0.02466*(法兰厚度C+4)/1000。*/
        int M = 0;
        Double flnj = Double.parseDouble(generaFlnj(flnj1, flnj2));
        Double flwjD2 = Double.parseDouble(flwjD);
        Double flhdC2 = Double.parseDouble(flhdC);
        Double gctjDn2 = Double.parseDouble(gctjDn.replace("\"",""));
        Double val =  (flwjD2-flnj)/2;
        if(!StringUtils.isEmpty(fltgF)&&!"0".equals(fltgF)){
            if(gctjDn2<=600){
                /*1、(法兰外径D-法兰内径)/2≤80，M+2*/

                if(val<=80){
                    M = 2;
                }
                /*2、80＜(法兰外径D-法兰内径)/2≤100，M+3*/
                if(val>80&&val<=100){
                    M = 3;
                }
                /*3、(法兰外径D-法兰内径)/2＞100，M+4。*/
                if(val>100){
                    M = 4;
                }
            }else if(gctjDn2>600 && gctjDn2<=800){
                if(val<=80){
                    M = 3;
                }

                if(val>80&&val<=100){
                    M = 4;
                }

                if(val>100){
                    M = 5;
                }
            }else if(gctjDn2>800){
                if(val<=80){
                    M = 4;
                }

                if(val>80&&val<=100){
                    M = 5;
                }

                if(val>100){
                    M = 6;
                }
            }
        }else{
            if(gctjDn2<=600){
                if(val<=80){
                    M = 4;
                }

                if(val>80&&val<=100){
                    M = 5;
                }

                if(val>100){
                    M = 6;
                }
            }else if(gctjDn2>600 && gctjDn2<=800){
                if(val<=80){
                    M = 5;
                }

                if(val>80&&val<=100){
                    M = 6;
                }

                if(val>100){
                    M = 7;
                }
            }else if(gctjDn2>800){
                if(val<=80){
                    M = 6;
                }

                if(val>80&&val<=100){
                    M = 7;
                }

                if(val>100){
                    M = 8;
                }
            }
        }
        xlzl = (flwjD2+10-(((flwjD2+10)-(flnj-10))/2))*(((flwjD2+10)-(flnj-10))/2)*0.02466*(flhdC2+M)/1000;
        BigDecimal two = new BigDecimal(xlzl);
        double resultDouble = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        return resultDouble;
    }


}
